
def prostoe(n):
    if n <= 1:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True

def naiti_prostoe(number):
    chislo_str = str(number)
    prostbIe = [int(chislo_str[i:j]) for i in range(len(chislo_str)) for j in range(i + 1, len(chislo_str) + 1) if prostoe(int(chislo_str[i:j]))]
    return prostbIe

number = int(input('введи число: '))
if number < 1000 or number > 9999:
    print('0')
else:
    prostbIe_in_chislo = naiti_prostoe(number)
    if prostbIe_in_chislo == []:
        print('0')
    else:
        print(max(prostbIe_in_chislo))
